﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}
<script src="~/Content/scripts/utils/LeSoft-ui.js"></script>
<script>
    var keyValue = request('keyValue');
    var ChooseTime;
    $(function () {
        initControl();
    }) 
    function initControl() {
        //当前状态
        $("#State").ComboBox({
            data: [{ "key": 1, "value": "有效" }, { "key": 2, "value": "已经签约" }, { "key": 3, "value": "已取消" }],
            id: "key",
            text: "value",
            height: "150px"
        });
        $("#State").ComboBoxSetValue(1);
        //获取表单
        if (!!keyValue) {
            $("#State").attr("disabled", "disabled");
            $.SetForm({
                url: "../../QualificationManage/SelectRoomRecord/GetEntity",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data.selectRoomRecordEntity);
                    $("#State").ComboBoxSetValue(data.selectRoomRecordEntity.State);
                    ChooseTime = data.selectRoomRecordEntity.ChooseTime;
                    $("#ChooseTime").attr("disabled", "disabled");
                    $("#Name").val(data.memberEntity.Name);
                    $("#AllName").val(data.pstructEntity.AllName);
                    $("#MemberCode").val(data.memberEntity.Code);
                    $("#Phone").val(data.memberEntity.Phone);
                    if (!!data.contractEntity) {
                        $("#ContractCode").val(data.contractEntity.Code);
                        $("#ContractId").val(data.contractEntity.Id);
                    }
                    $(".BaseClass").attr("disabled", "disabled").removeAttr("onclick");
                    $("#ContractCode").attr("readonly", "readonly");
                }
            });
        }
    }

    function GetDataSelect(Type) {
        var options = {};
        var queryJson = {
            IsPublish: 1
        };
        switch (Type) {
            case 1:
                options["type"] = 5;
                options["data"] = [{ "id": "AllName" }];
                options["organizeid"] = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
                options["PstructType"] = 8;
                options["queryJson"] = "T";
                break;
            case 2:
                options["type"] = 4;
                options["data"] = [{ "id": "Name" }, { "id": "MemberCode" }, { "id": "Phone" }];
                options["organizeid"] = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
                break;
            default:

        }
        DataItemClick(JSON.stringify(options));
    }

    function Change() {
        var date = new Date($("#ChooseTime").val());
        date.setDate(date.getDate() + 3);
        $("#CancelTime").val(formatDate(date, 'yyyy-MM-dd'));
    }

    //保存表单
    function AcceptClick(obj) {
        if (!$('#SelectRoomInfo').Validform()) {
            return false;
        }
        var postData = $("#SelectRoomInfo").GetWebControls(keyValue);
        if (!!keyValue) {
            postData = {};
            postData["CancelTime"] = $("#CancelTime").val();
            postData["State"] = $("#State").attr("data-value");
            postData["ChooseTime"] = ChooseTime;
        }
        else {
            postData["RoomId"] = $("#AllName").attr("title");
            postData["MemberId"] = $("#Name").attr("title");
            postData["SourceId"] = $("#ContractCode").val();
            postData["ContractId"] = $("ContractId").val();
        }
        $.ConfirmAjax({
            msg: "注：您确认要进行此操作吗？",
            url: "../../QualificationManage/SelectRoomRecord/SaveForm?keyValue=" + keyValue,
            param: postData,
            loading: "正在保存数据...",
            success: function () {
                $.currentIframe().$("#gridTable").resetSelection();
                $.currentIframe().$("#gridTable").trigger("reloadGrid");
                dialogClose();
            }
        }); 

    };
</script>
<div style="margin-top: 20px; margin-right: 30px;">
    <table class="form" id="SelectRoomInfo" style="margin-top: 20px;">
        <tr>
            <td class="formTitle">房间名称<font face="宋体">*</font></td>
            <td class="formValue">
                <div class="input-group" style="width: 100%;">
                    <input id="AllName" type="text" readonly="readonly" isvalid="yes" checkexpession="NotNull" class="form-control  BaseClass">
                    <span class="input-group-btn">
                        <a onclick="GetDataSelect(1)" class="form-control  BaseClass"  style="cursor: pointer"><i class="fa fa fa-book BaseClass  " style=" font-size: 20px; padding-right: 5px;   color: gray"></i></a>
                    </span>
                </div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">会员名称<font face="宋体">*</font></td>
            <td class="formValue">
                <div class="input-group" style="width: 100%;">
                    <input id="Name" type="text" readonly="readonly" isvalid="yes" checkexpession="NotNull"  class="form-control  BaseClass">
                    <span class="input-group-btn">
                        <a onclick="GetDataSelect(2)" class="form-control  BaseClass" style="cursor: pointer"><i class="fa fa fa-book BaseClass  " style=" font-size: 20px; padding-right: 5px;   color: gray"></i></a>
                    </span>
                </div>
            </td>
        </tr>
        <tr>
            <td class="formTitle">会员编号</td>
            <td class="formValue">
                <input id="MemberCode" type="text" class="form-control" readonly="readonly" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">会员手机号</td>
            <td class="formValue">
                <input id="Phone" type="text" class="form-control" readonly="readonly" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">合同编号</td>
            <td class="formValue">
                <input id="ContractId" type="hidden" />
                <input id="ContractCode" type="text" class="form-control" readonly="readonly" isvalid="yes" checkexpession="IsScript" />
            </td>
        </tr>
        <tr>
            <th class="formTitle">选房时间</th>
            <td class="formValue">
                <input id="ChooseTime" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" onchange="Change()" isvalid="yes" checkexpession="IsScript" value="@DateTime.Now.ToString("yyyy-MM-dd")" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">状态</td>
            <td class="formValue">
                <div id="State" type="select" class="ui-select" disabled isvalid="yes" checkexpession="NotNull"></div>
            </td>
        </tr>
        <tr>
            <th class="formTitle">到期时间<font face="宋体">*</font></th>
            <td class="formValue">
                     <input id="CancelTime" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'ChooseTime\')}' })" isvalid="yes" checkexpession="NotNull" value="@LeSoft.Application.Service.QualificationBillService.GetWorkTime(DateTime.Now,5,6000)" />
            </td>
        </tr>
    </table>
</div>
